﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Trans.depart;

namespace Trans.member
{
    public partial class Add_member : Form
    {
        DataRowView row;
        public Add_member()
        {
            InitializeComponent();
        }

        private void Add_member_Load(object sender, EventArgs e)
        {
            row=(DataRowView)tbmemberBindingSource.AddNew();
        }

        private void bt_add_Click(object sender, EventArgs e)
        {
            if (this.ValidateChildren())
            {


                try
                {

                    tbmemberBindingSource.EndEdit();
                    tb_memberTableAdapter.Update(dataSet.tb_member);
                    this.Close();
                    MessageBox.Show("添加成功", "", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
                catch (System.Exception ex)
                {
                    MessageBox.Show("出错啦" + ex.Message, "", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }

        private void bt_cancel_Click(object sender, EventArgs e)
        {
            tbmemberBindingSource.CancelEdit();
            this.Close();
        }

        private void bt_depart_Click(object sender, EventArgs e)
        {
            Select_depart f = new Select_depart();
            f.ShowDialog();
            if(f.HasSelected)
            {
                lb_depart.Text = f.Name_s;
                row["depart_id"] = f.Id;
            }
        }

        private void tx_passwd_Validating(object sender, CancelEventArgs e)
        {
            if(tx_passwd.Text.Length==0)
            {
                error.SetError(tx_passwd, "请填写密码");
                e.Cancel=true;
            }
            else
            {
                error.SetError(tx_passwd, "");
            }
        }

        private void tx_userid_Validating(object sender, CancelEventArgs e)
        {
            if (tx_userid.Text.Length == 0)
            {
                error.SetError(tx_userid, "请填写用户名");
                e.Cancel = true;
            }
            else
            {
                error.SetError(tx_userid, "");
            }
        }

        private void tx_name_Validating(object sender, CancelEventArgs e)
        {
            if (tx_name.Text.Length == 0)
            {
                error.SetError(tx_name, "请填写名称");
                e.Cancel = true;
            }
            else
            {
                error.SetError(tx_name, "");
            }
        }
    }
}
